<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>取得文件的权限</title>
 </head>
 <body class="docs"><div id="layout">
  <div id="layout-content"><div id="function.fileperms" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">fileperms</h1>
  <p class="verinfo">(PHP 4, PHP 5, PHP 7)</p><p class="refpurpose"><span class="refname">fileperms</span> &mdash; <span class="dc-title">取得文件的权限</span></p>

 </div>
 
 <div class="refsect1 description" id="refsect1-function.fileperms-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>fileperms</strong></span>
    ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$filename</code></span>
   ) : <span class="type">int</span></div>

  <p class="para rdfs-comment">
   取得文件的权限。
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.fileperms-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>

    
     <dt>
<code class="parameter">filename</code></dt>

     <dd>

      <p class="para">
       文件的路径。
      </p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.fileperms-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   以数字模式返回文件的访问权限。
   Returns the file&#039;s permissions as a numeric mode. 
   
   Lower bits of this mode
   are the same as the permissions expected by <span class="function"><a href="chmod.html" class="function">chmod()</a></span>,
   however on most platforms the return value will also include information on
   the type of file given as <code class="parameter">filename</code>. The examples
   below demonstrate how to test the return value for specific permissions and
   file types on POSIX systems, including Linux and Mac OS X.
  </p>
  <p class="para">
   For local files, the specific return value is that of the
   <em>st_mode</em> member of the structure returned by the C
   library&#039;s <span class="function"><a href="stat.html" class="function">stat()</a></span> function. Exactly which bits are set
   can vary from platform to platform, and looking up your specific platform&#039;s
   documentation is recommended if parsing the non-permission bits of the
   return value is required.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.fileperms-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-2791">
    <p><strong>Example #1 以八进制的形式显示文件的权限</strong></p>
    <div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">echo&nbsp;</span><span style="color: #0000BB">substr</span><span style="color: #007700">(</span><span style="color: #0000BB">sprintf</span><span style="color: #007700">(</span><span style="color: #DD0000">'%o'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">fileperms</span><span style="color: #007700">(</span><span style="color: #DD0000">'/tmp'</span><span style="color: #007700">)),&nbsp;-</span><span style="color: #0000BB">4</span><span style="color: #007700">);<br />echo&nbsp;</span><span style="color: #0000BB">substr</span><span style="color: #007700">(</span><span style="color: #0000BB">sprintf</span><span style="color: #007700">(</span><span style="color: #DD0000">'%o'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">fileperms</span><span style="color: #007700">(</span><span style="color: #DD0000">'/etc/passwd'</span><span style="color: #007700">)),&nbsp;-</span><span style="color: #0000BB">4</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></div>
    </div>

    <div class="example-contents"><p>以上例程会输出：</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
1777
0644
</pre></div>
    </div>
   </div>
   <div class="example" id="example-2792">
    <p><strong>Example #2 输出全部权限</strong></p>
    <div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$perms&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">fileperms</span><span style="color: #007700">(</span><span style="color: #DD0000">'/etc/passwd'</span><span style="color: #007700">);<br /><br />if&nbsp;((</span><span style="color: #0000BB">$perms&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">0xC000</span><span style="color: #007700">)&nbsp;==&nbsp;</span><span style="color: #0000BB">0xC000</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;Socket<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$info&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'s'</span><span style="color: #007700">;<br />}&nbsp;elseif&nbsp;((</span><span style="color: #0000BB">$perms&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">0xA000</span><span style="color: #007700">)&nbsp;==&nbsp;</span><span style="color: #0000BB">0xA000</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;Symbolic&nbsp;Link<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$info&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'l'</span><span style="color: #007700">;<br />}&nbsp;elseif&nbsp;((</span><span style="color: #0000BB">$perms&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">0x8000</span><span style="color: #007700">)&nbsp;==&nbsp;</span><span style="color: #0000BB">0x8000</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;Regular<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$info&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'-'</span><span style="color: #007700">;<br />}&nbsp;elseif&nbsp;((</span><span style="color: #0000BB">$perms&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">0x6000</span><span style="color: #007700">)&nbsp;==&nbsp;</span><span style="color: #0000BB">0x6000</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;Block&nbsp;special<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$info&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'b'</span><span style="color: #007700">;<br />}&nbsp;elseif&nbsp;((</span><span style="color: #0000BB">$perms&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">0x4000</span><span style="color: #007700">)&nbsp;==&nbsp;</span><span style="color: #0000BB">0x4000</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;Directory<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$info&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'d'</span><span style="color: #007700">;<br />}&nbsp;elseif&nbsp;((</span><span style="color: #0000BB">$perms&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">0x2000</span><span style="color: #007700">)&nbsp;==&nbsp;</span><span style="color: #0000BB">0x2000</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;Character&nbsp;special<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$info&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'c'</span><span style="color: #007700">;<br />}&nbsp;elseif&nbsp;((</span><span style="color: #0000BB">$perms&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">0x1000</span><span style="color: #007700">)&nbsp;==&nbsp;</span><span style="color: #0000BB">0x1000</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;FIFO&nbsp;pipe<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$info&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'p'</span><span style="color: #007700">;<br />}&nbsp;else&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;Unknown<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$info&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'u'</span><span style="color: #007700">;<br />}<br /><br /></span><span style="color: #FF8000">//&nbsp;Owner<br /></span><span style="color: #0000BB">$info&nbsp;</span><span style="color: #007700">.=&nbsp;((</span><span style="color: #0000BB">$perms&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">0x0100</span><span style="color: #007700">)&nbsp;?&nbsp;</span><span style="color: #DD0000">'r'&nbsp;</span><span style="color: #007700">:&nbsp;</span><span style="color: #DD0000">'-'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$info&nbsp;</span><span style="color: #007700">.=&nbsp;((</span><span style="color: #0000BB">$perms&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">0x0080</span><span style="color: #007700">)&nbsp;?&nbsp;</span><span style="color: #DD0000">'w'&nbsp;</span><span style="color: #007700">:&nbsp;</span><span style="color: #DD0000">'-'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$info&nbsp;</span><span style="color: #007700">.=&nbsp;((</span><span style="color: #0000BB">$perms&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">0x0040</span><span style="color: #007700">)&nbsp;?<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;((</span><span style="color: #0000BB">$perms&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">0x0800</span><span style="color: #007700">)&nbsp;?&nbsp;</span><span style="color: #DD0000">'s'&nbsp;</span><span style="color: #007700">:&nbsp;</span><span style="color: #DD0000">'x'&nbsp;</span><span style="color: #007700">)&nbsp;:<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;((</span><span style="color: #0000BB">$perms&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">0x0800</span><span style="color: #007700">)&nbsp;?&nbsp;</span><span style="color: #DD0000">'S'&nbsp;</span><span style="color: #007700">:&nbsp;</span><span style="color: #DD0000">'-'</span><span style="color: #007700">));<br /><br /></span><span style="color: #FF8000">//&nbsp;Group<br /></span><span style="color: #0000BB">$info&nbsp;</span><span style="color: #007700">.=&nbsp;((</span><span style="color: #0000BB">$perms&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">0x0020</span><span style="color: #007700">)&nbsp;?&nbsp;</span><span style="color: #DD0000">'r'&nbsp;</span><span style="color: #007700">:&nbsp;</span><span style="color: #DD0000">'-'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$info&nbsp;</span><span style="color: #007700">.=&nbsp;((</span><span style="color: #0000BB">$perms&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">0x0010</span><span style="color: #007700">)&nbsp;?&nbsp;</span><span style="color: #DD0000">'w'&nbsp;</span><span style="color: #007700">:&nbsp;</span><span style="color: #DD0000">'-'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$info&nbsp;</span><span style="color: #007700">.=&nbsp;((</span><span style="color: #0000BB">$perms&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">0x0008</span><span style="color: #007700">)&nbsp;?<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;((</span><span style="color: #0000BB">$perms&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">0x0400</span><span style="color: #007700">)&nbsp;?&nbsp;</span><span style="color: #DD0000">'s'&nbsp;</span><span style="color: #007700">:&nbsp;</span><span style="color: #DD0000">'x'&nbsp;</span><span style="color: #007700">)&nbsp;:<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;((</span><span style="color: #0000BB">$perms&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">0x0400</span><span style="color: #007700">)&nbsp;?&nbsp;</span><span style="color: #DD0000">'S'&nbsp;</span><span style="color: #007700">:&nbsp;</span><span style="color: #DD0000">'-'</span><span style="color: #007700">));<br /><br /></span><span style="color: #FF8000">//&nbsp;World<br /></span><span style="color: #0000BB">$info&nbsp;</span><span style="color: #007700">.=&nbsp;((</span><span style="color: #0000BB">$perms&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">0x0004</span><span style="color: #007700">)&nbsp;?&nbsp;</span><span style="color: #DD0000">'r'&nbsp;</span><span style="color: #007700">:&nbsp;</span><span style="color: #DD0000">'-'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$info&nbsp;</span><span style="color: #007700">.=&nbsp;((</span><span style="color: #0000BB">$perms&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">0x0002</span><span style="color: #007700">)&nbsp;?&nbsp;</span><span style="color: #DD0000">'w'&nbsp;</span><span style="color: #007700">:&nbsp;</span><span style="color: #DD0000">'-'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$info&nbsp;</span><span style="color: #007700">.=&nbsp;((</span><span style="color: #0000BB">$perms&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">0x0001</span><span style="color: #007700">)&nbsp;?<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;((</span><span style="color: #0000BB">$perms&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">0x0200</span><span style="color: #007700">)&nbsp;?&nbsp;</span><span style="color: #DD0000">'t'&nbsp;</span><span style="color: #007700">:&nbsp;</span><span style="color: #DD0000">'x'&nbsp;</span><span style="color: #007700">)&nbsp;:<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;((</span><span style="color: #0000BB">$perms&nbsp;</span><span style="color: #007700">&amp;&nbsp;</span><span style="color: #0000BB">0x0200</span><span style="color: #007700">)&nbsp;?&nbsp;</span><span style="color: #DD0000">'T'&nbsp;</span><span style="color: #007700">:&nbsp;</span><span style="color: #DD0000">'-'</span><span style="color: #007700">));<br /><br />echo&nbsp;</span><span style="color: #0000BB">$info</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></div>
    </div>

    <div class="example-contents"><p>以上例程会输出：</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
-rw-r--r--
</pre></div>
    </div>
   </div>
  </p>
 </div>


 <div class="refsect1 errors" id="refsect1-function.fileperms-errors">
  <h3 class="title">错误／异常</h3>
  <p class="para">
失败时抛出<strong><code>E_WARNING</code></strong>警告。
</p>
 </div>


 <div class="refsect1 notes" id="refsect1-function.fileperms-notes">
  <h3 class="title">注释</h3>
  <blockquote class="note"><p><strong class="note">Note</strong>: <span class="simpara">此函数的结果会被缓存。参见
<span class="function"><a href="clearstatcache.html" class="function">clearstatcache()</a></span> 以获得更多细节。</span></p></blockquote>
  <div class="tip"><strong class="tip">Tip</strong><p class="simpara">自 PHP 5.0.0 起, 此函数也用于<em class="emphasis">某些</em>
URL 包装器。请参见 <a href="wrappers.html" class="xref">支持的协议和封装协议</a>以获得支持 <span class="function"><a href="stat.html" class="function">stat()</a></span> 系列函数功能的包装器列表。</p></div>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.fileperms-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="chmod.html" class="function" rel="rdfs-seeAlso">chmod()</a> - 改变文件模式</span></li>
    <li class="member"><span class="function"><a href="is_readable.html" class="function" rel="rdfs-seeAlso">is_readable()</a> - 判断给定文件名是否可读</span></li>
    <li class="member"><span class="function"><a href="stat.html" class="function" rel="rdfs-seeAlso">stat()</a> - 给出文件的信息</span></li>
   </ul>
  </p>
 </div>

</div></div></div></body></html>